# 导入requests库
import requests
# 设置爬取的网页URL
url = "https://news.ncu.edu.cn/ndyw/index1.htm"
# 发送GET请求获取网页内容
response = requests.get(url)
# 设置网页编码
response.encoding = response.apparent_encoding  # 自动识别编码
# 判断请求是否成功
if response.status_code == 200:# 200表示请求成功
    # 将网页内容写入本地文件
    with open("index1.htm", "w", encoding=response.encoding) as f:
        f.write(response.text)
    print("页面已保存为 index1.htm")
    print(response.encoding)
else:# 失败时打印失败原因
    print(f"请求失败，状态码: {response.status_code}")